package com.gimi.cloud.bbp.app.consumer.controller;

import com.gimi.cloud.bbp.app.consumer.service.sys.PublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件路径转发
 *
 * @author wbj
 * @version 1.0
 * @Descriion
 * @create 2018-02-01
 **/
@Controller
@RequestMapping("/file")
public class GetFileController {
    private final PublicService publicService;

    @Autowired
    public GetFileController(PublicService publicService) {
        this.publicService = publicService;
    }

    /**
     * 根据文件名获取文件
     * @param fileName
     * @return
     */
    @RequestMapping("/path")
    public String getFile(HttpServletRequest request, HttpServletResponse response,String fileName) {
        return "redirect:" +publicService.getFilePath(request,response,fileName);
    }
}
